//未完待续
import 'package:flutter/material.dart';
import 'package:flutter_mwm/util/util.dart';
import 'package:flutter_spinkit/flutter_spinkit.dart';

/*对话框*/
class ProgressWidget extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    return _ProgressState();
  }
}

class _ProgressState extends State<ProgressWidget> {
  @override
  Widget build(BuildContext context) {
    return Center(
      child: CircularProgressIndicator(),
    );
  }
}

///加载控件
class ProgressView extends StatelessWidget {
  final String text;
  final GestureTapCallback callback;
  final bool outSideCancel;

  ProgressView(this.text, this.callback, {this.outSideCancel = false});

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
        onTap: outSideCancel ? callback : null,
        child: Container(
            alignment: Alignment.center,
            color: Colors.black45,
            padding: EdgeInsets.symmetric(vertical: 5.0, horizontal: 10.0),
            child: _dialog(context)));
  }

  Widget _dialog(BuildContext context) {
    double width = MediaQuery.of(context).size.width / 1.2;
    return Container(
      width: width,
      height: width / 3,
      decoration: BoxDecoration(
        color: Colors.white,
        borderRadius: BorderRadius.all(Radius.circular(8.0)),
      ),
      child: Column(
        mainAxisAlignment: MainAxisAlignment.center,
        children: <Widget>[
          SpinKitPouringHourglass(
            color: Colors.green,
            size: 60.0,
          ),
          Padding(padding: EdgeInsets.all(8.0)),
          Text(TextUtils.replaceNull(text),
              style: TextStyle(
                  decoration: TextDecoration.none,
                  color: Colors.lightBlueAccent,
                  fontSize: 16.0))
        ],
      ),
    );
  }
}

class LoadingWidget extends StatelessWidget {
  final String loadingText;

  const LoadingWidget({this.loadingText = ""});

  @override
  Widget build(BuildContext context) {
    return Container(child: Center(child: CircularProgressIndicator()));
  }
}
